import { createRouter, createWebHistory } from "vue-router";
import { h, resolveComponent } from "vue";
import NotFound from "./views/404.vue";
import NProgress from "nprogress";
import "nprogress/nprogress.css";

const router = new createRouter({
  history: createWebHistory(""),
  routes: [
    {
      path: "/user",
      hideInMenu: true,
      component: () =>
        import(/* webpackChunkName:"layout"*/ "./layouts/UserLayout"),
      children: [
        {
          path: "/user",
          redirect: "/user/login",
        },
        {
          path: "/user/login",
          name: "login",
          component: () =>
            import(/* webpackChunkName:"user"*/ "./views/User/Login"),
        },
        {
          path: "/user/register",
          name: "register",
          component: () =>
            import(/* webpackChunkName:"user"*/ "./views/User/Register"),
        },
      ],
    },
    {
      path: "/",
      component: () =>
        import(/* webpackChunkName:"layout" */ "./layouts/BasicLayout"),
      children: [
        //dashboard
        {
          path: "/",
          redirect: "dashboard/analysis",
        },
        {
          path: "/dashboard",
          name: "dashboard",
          meta: { icon: "dashboard", title: "仪表盘" },
          component: {
            render() {
              return h(resolveComponent("router-view"));
            },
          },
          children: [
            {
              path: "/dashboard/analysis",
              name: "analyasis",
              meta: { title: "分析页" },
              component: () =>
                import(
                  /* webpackChunkName:"dashboard"*/ "./views/Dashboard/Analysis"
                ),
            },
          ],
        },
        //form
        {
          path: "/form",
          name: "form",
          component: {
            render() {
              return h(resolveComponent("router-view"));
            },
          },
          meta: { icon: "form", title: "表单" },
          children: [
            {
              path: "/form/basic-form",
              name: "basicform",
              meta: { title: "基础表单" },
              component: () =>
                import(/* webpackChunkName:"form"*/ "./views/Forms/BasicForm"),
            },
            {
              path: "/form/step-form",
              name: "stepform",
              meta: { title: "分步表单" },
              hideChildrenMenu: true,
              component: () =>
                import(/* webpackChunkName:"form"*/ "./views/Forms/StepForm"),
              children: [
                {
                  path: "/form/step-form",
                  redirect: "/form/step-form/info",
                },
                {
                  path: "/form/step-form/info",
                  name: "info",
                  component: () =>
                    import(
                      /* webpackChunkName:"form"*/ "./views/Forms/StepForm/Step1"
                    ),
                },
                {
                  path: "/form/step-form/confirm",
                  name: "confirm",
                  component: () =>
                    import(
                      /* webpackChunkName:"form"*/ "./views/Forms/StepForm/Step2"
                    ),
                },
                {
                  path: "/form/step-form/result",
                  name: "result",
                  component: () =>
                    import(
                      /* webpackChunkName:"form"*/ "./views/Forms/StepForm/Step3"
                    ),
                },
              ],
            },
          ],
        },
      ],
    },
    {
      // path: "*",
      path: "/:catchAll(.*)",
      name: "NotFound",
      hideInMenu: true,
      component: NotFound,
      meta: {
        requiresAuth: false,
      },
    },
  ],
});
router.beforeEach((to, from, next) => {
  if (to.path !== from.path) {
    NProgress.start();
  }

  next();
});
router.afterEach(() => {
  NProgress.done;
});
export default router;
